package thread;

import com.ms.common.utils.ThreadUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * 线程中六种状态
 *
 * @author ganbo
 * @date 2022/10/18 19:16
 */
@Slf4j
public class ThreadStatu {


    public static void main(String[] args) {


        Thread t1 = new Thread("t1") {
            @Override
            public void run() {
                log.debug("running");
            }
        };

        Thread t2 = new Thread(() -> {
            while (true) {

            }
        }, "t2");
        t2.start();


        Thread t3 = new Thread(() -> {
            System.out.println("t3-");
        }, "t3");
        t3.start();

        Thread t4 = new Thread(() -> {
            synchronized (ThreadStatu.class) {
                ThreadUtils.sleepSeconds(3);
            }
        }, "t4");
        t4.start();

        Thread t5 = new Thread(() -> {
            try {
                t2.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "t5");
        t5.start();

        Thread t6 = new Thread(() -> {
            synchronized (ThreadStatu.class) {
                ThreadUtils.sleepSeconds(5);
            }
        }, "t6");
        t6.start();


        ThreadUtils.sleepSeconds(2);

        log.debug("name:{}, status:{}", t1.getName(), t1.getState().name());
        log.debug("name:{}, status:{}", t2.getName(), t2.getState().name());
        log.debug("name:{}, status:{}", t3.getName(), t3.getState().name());
        log.debug("name:{}, status:{}", t4.getName(), t4.getState().name());
        log.debug("name:{}, status:{}", t5.getName(), t5.getState().name());
        log.debug("name:{}, status:{}", t6.getName(), t6.getState().name());
    }


}
